//
//  YCTeachPlanViewController.m
//  YCSchool
//
//  Created by gmall on 16/5/24.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//  教学计划

#import "YCTeachPlanViewController.h"
#import "YCTeachPlanDetailViewController.h"
#import "YCTrainPlanCell.h"
#import "YCTeachPlanModel.h"

@interface YCTeachPlanViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *itemsArray;
@end

@implementation YCTeachPlanViewController

- (NSMutableArray *)itemsArray
{
    if (!_itemsArray) {
        _itemsArray = [NSMutableArray array];
        
        YCTeachPlanModel *model = [[YCTeachPlanModel alloc] init];
        model.finishmark = YES;
        model.todayTrain = NO;
        model.timeday = 15;
        model.timemonth = @"4月";
        model.title = @"静地训练 静机";
        model.addtime = 2342343;
        
        YCTeachPlanModel *model1 = [[YCTeachPlanModel alloc] init];
        model1.finishmark= NO;
        model1.todayTrain = YES;
        model1.timeday = 19;
        model1.timemonth = @"4月";
        model1.title = @"场地训练 半坡起步";
        model1.addtime = 2342343;
        
        YCTeachPlanModel *model2 = [[YCTeachPlanModel alloc] init];
        model2.finishmark = NO;
        model2.todayTrain = NO;
        model2.timeday = 24;
        model2.timemonth = @"4月";
        model2.title = @"场地训练 侧位停车";
        model2.addtime = 2342343;
        
        YCTeachPlanModel *model3 = [[YCTeachPlanModel alloc] init];
        model3.finishmark = NO;
        model3.todayTrain = NO;
        model3.timeday = 28;
        model3.timemonth = @"4月";
        model3.title = @"场地地训练 曲线行驶";
        model3.addtime = 2342343;
        
        [_itemsArray addObjectsFromArray:@[model,model1,model2,model3]];
        
    }
    return _itemsArray;
}

- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.yc_width, self.view.yc_height - 64) style:UITableViewStylePlain];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.backgroundColor = [UIColor yc_colorWithUInt:0xf2f2f2];
        UINib *nib = [UINib nibWithNibName:NSStringFromClass([YCTrainPlanCell class]) bundle:nil];
        [_tableView registerNib:nib forCellReuseIdentifier:@"trainPlanCell"];
        
    }
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"教学计划";
    [self yc_addLeftBarButtonItemWithTitle:@"关闭" target:self action:@selector(back)];
    [self.view addSubview:self.tableView];
    self.tableView.contentInset = UIEdgeInsetsMake(5, 0, 0, 0);
    self.tableView.rowHeight = 100;
    //    YCWeakSelf;
    //    self.tableView.mj_header = [YCRefreshHeader headerWithRefreshingBlock:^{
    //        [weakSelf loadData];
    //    }];
    //    [self.tableView.mj_header beginRefreshing];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - 数据处理
- (void)loadData
{
    NSDictionary *params = @{
                             @"uid":@"1",
                             @"token":accessToken_Test,
                             };
    [[YCNetworManager shareManager] postWithUrl:YCAPITrainPlanList params:params success:^(NSURLSessionDataTask *task, ServiceResponse *response) {
        self.itemsArray = [YCTrainPlanModel yc_objectArrayWithKeyValuesArray:response.data];
        [self.tableView reloadData];
        [self.tableView.mj_header endRefreshing];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        YCLog(@"%@",error.localizedDescription);
        [self.tableView.mj_header endRefreshing];
    }];
}

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.itemsArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YCTrainPlanCell *cell = [tableView dequeueReusableCellWithIdentifier:@"trainPlanCell"];
    cell.contentView.backgroundColor = [UIColor yc_colorWithUInt:0xf2f2f2];
    cell.itemModel = self.itemsArray[indexPath.row];
    return cell;
}

#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    YCTeachPlanDetailViewController *detailVc = [[YCTeachPlanDetailViewController alloc] init];
    [self.navigationController pushViewController:detailVc animated:YES];
}


#pragma mark - 点击事件
- (void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}



@end
